<div class="widget editor-widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 客户跟进 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-customer"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 跟进记录 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-selling">
			<div class="widget-header bg-gold">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 跟进记录 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-info btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									onclick="handlerAddRow('#table-selling')">
						<i class="fa fa-plus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="table-editor table-editor-selling" method="post">
					<table data-ajax="handlerSearch" data-method="post"
								 data-id-field="id" 
								 data-unique-id="id" 
								 data-pagination="true"  
								 data-check-on-init="true" 
								 data-side-pagination="server" 
								 data-mobile-responsive="true" 
								 data-form-source=".table-editor-selling" 
								 data-form-target="#editor-form-selling" 
								 data-form-search="#search-form-selling" id="table-selling">
						<thead>
							<tr>
								<th data-checkbox="true"></th>
								<th data-field="id" data-visible="false"></th>
								<th data-field="createDate" data-align="center">通话时间</th>
								<th data-field="intention" 	data-align="center" data-formatter="renderIntention">意向程度</th>
								<th data-field="content" 		data-align="center">跟踪情况</th>
								<th data-field="nextDate" 	data-align="center">下次沟通时间</th>
								<th data-field="username" 	data-align="center">顾问</th>
								<th data-field="userid" 		data-align="center" data-visible="false">顾问ID</th>
								<th data-field="operator" 	data-align="center" data-width="30" data-formatter="renderOperator" data-table-target="selling">操作</th>
							</tr>
						</thead>
					</table>
				</form>
			</div>
		</div>
		<!-- TODO 诺访记录 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-bespoke">
			<div class="widget-header bg-gold">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 诺访记录 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-info btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									onclick="intercept('#table-bespoke')">
						<i class="fa fa-plus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="table-editor table-editor-bespoke">
					<table data-ajax="handlerSearch" data-method="post"
								 data-id-field="id" 
								 data-unique-id="id" 
								 data-pagination="true"  
								 data-check-on-init="true" 
								 data-side-pagination="server" 
								 data-mobile-responsive="true" 
								 data-form-source=".table-editor-bespoke" 
								 data-form-target="#editor-form-bespoke" 
								 data-form-search="#search-form-bespoke" id="table-bespoke">
						<thead>
							<tr>
								<th data-checkbox="true"></th>
								<th data-field="id" data-visible="false"></th>
								<th data-field="createDate" 	data-align="center">预约时间</th>
								<th data-field="bespokeType" 	data-align="center" data-formatter="renderAudition">预约内容</th>
								<th data-field="promiseDate" 	data-align="center">诺访时间</th>
								<th data-field="commingDate" 	data-align="center" data-formatter="renderComming">到店情况</th>
								<th data-field="username" 		data-align="center">顾问</th>
								<th data-field="userid" 			data-align="center" data-visible="false">顾问ID</th>
								<th data-field="operator" 		data-align="center" data-width="30" data-formatter="renderOperator" data-table-target="bespoke">操作</th>
							</tr>
						</thead>
					</table>
				</form>
			</div>
		</div>
		
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-customer">
				
			</div>
		</div>
		<!-- TODO 家长信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header" id="">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 家长信息 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="append" 
									data-template-id="#form-parent-template" 
									data-template-path="/miwawa/content/portal/customer/template.html" 
									data-template-target=".editor-body-parents"
									data-loaded="handlerParents">
						<i class="fa fa-plus"></i>
					</button>
					<button class="btn btn-default btn-sm" title="删除" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="remove" data-template-target=".editor-body-parents">
						<i class="fa fa-minus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-parents" id="editor-parentss">
				<!-- dynamic data -->
			</div>
		</div>
		<!-- TODO 宝宝信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 宝宝信息 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="append" 
									data-template-id="#form-student-template" 
									data-template-path="/miwawa/content/portal/customer/template.html" 
									data-template-target=".editor-body-student"
									data-loaded="handlerStudent">
						<i class="fa fa-plus"></i>
					</button>
					<button class="btn btn-default btn-sm" title="删除" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="remove" data-template-target=".editor-body-student">
						<i class="fa fa-minus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-student">
				<!-- dynamic data -->
			</div>
		</div>
		<!-- TODO 家庭住址 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 家庭住址 </a> </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-address">
				<!-- dynamic data -->
			</div>
		</div>
		
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="update-form-customer" action="/miwawa/{dbname}/common/update" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Customer">
</form>
<form id="editor-form-parents" action="/miwawa/{dbname}/parents/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Parents"
			data-custom-action="true">
</form>
<form id="update-form-parents" action="/miwawa/{dbname}/parents/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Parents"
			data-custom-action="true">
</form>
<form id="editor-form-student" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Student">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<form id="update-form-student" action="/miwawa/{dbname}/common/update" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Student">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<form id="editor-form-address" action="/miwawa/{dbname}/common/update" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Address">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<form id="editor-form-selling" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Selling">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<form id="editor-form-bespoke" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Bespoke">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<!-- 查询表单 ========================================================= -->
<form id="search-form-parents" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Parents" 
			data-template-target=".editor-body-parents" data-template-id="#view-parents-template" 
			data-template-path="/miwawa/content/portal/customer/template.html">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="status" data-search-order="desc">
</form>
<form id="search-form-student" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Student" 
			data-template-target=".editor-body-student" data-template-id="#view-student-template" 
			data-template-path="/miwawa/content/portal/customer/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
</form>
<form id="search-form-address" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Address" 
			data-template-target=".editor-body-address" data-template-id="#view-address-template" 
			data-template-path="/miwawa/content/portal/customer/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
</form>
<form id="search-form-selling" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Selling">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="createDate" data-search-order="desc">
</form>
<form id="search-form-bespoke" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.view.AuditionView">
			<input type="hidden" name="customerId" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="createDate" data-search-order="desc">
</form>

<script type="text/javascript">
<!--
	require(['domReady'],function(domReady){
		domReady(function () {
 			initData();
    });
	});
	var customer = jQuery("#table-customer").data("selectedRow");
	function initData(){
		jQuery(":hidden[name='customerId'],[data-foreign-id]").val(customer.customerid);
	
		jQuery(".editor-body-customer").loadform("load", {
			templateId: "#view-customer-template",
			templatePath: "/miwawa/content/portal/customer/template.html",
			templateData: customer,
			templateHelper:{
				"_market":function(value){
					require(['jquery.plugin.form'],function(form){
						form.chosen("#market").select("#market",{},function(chosen){
							jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
						});
					});
				},
				"_source":function(value){
					require(['jquery.plugin.form'],function(form){
						form.chosen("#source").select("#source",{},function(chosen){
							jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
						});
					});
				}
			}
		});
		
 		jQuery("#search-form-parents").loadform("many",{
			"_relation":function(value,index){
				require(['jquery.plugin.form'],function(form){
					form.chosen("#relation-"+index).select("#relation-"+index,{},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			}		
		}); 
		
		jQuery("#search-form-student").loadform("many",{
			"_sex":function(value,index){
				require(['jquery.plugin.form'],function(form){
					form.chosen("#sex-"+index).select("#sex-"+index,{},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			}
		});

		jQuery("#search-form-address").loadform("many",{
			"region":function(value){
				require(['jquery.plugin.form'],function(form){
					form.tooltip("[data-toggle='tooltip']");

					jQuery(".form-editor", ".editor-body-address").each(function(index,address){
						var _region = jQuery("#province,#prefecture,#county", address);
						form.chosen(_region).region(_region[2],{"pid":"310100"},function(chosen){
							jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
						});
					});
				});
			}
		});

		jQuery("#table-selling").bootstrapTable();
		
		jQuery("#table-bespoke").bootstrapTable({
			onLoadSuccess:function(data){
				require(['jquery.plugin.form'],function(form){
					form.tooltip("[data-toggle='tooltip']");
					form.datepicker('.date-selector',{format:'YYYY-MM-DD'});
				});
			}
		});
	}
	
	function judge(form){
		var parentForm = jQuery(".form-editor-parents");
		parentForm.each(function(i,n){
		 	if(i<=0){
				jQuery('#parStatus',form).val('true');
		 	}else{
				jQuery('#parStatus',form).val('false');
		 	} 
		});
 	}
	
	function intercept(target){
		jQuery.ajaxsend({
			url:"/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
			data:{
	       		"entityClass":"com.app.miwawa.api.esm.entity.customer.Bespoke",
	       	 	"and[0][operator]": "EQ",
	          "and[0][fieldName]": "customerId",					
	          "and[0][fieldValue]": customer.customerid
			},
			success:function(data){
				var bespoke = data.rows;
				for(var i=0;i<bespoke.length;i++){
					var come = bespoke[i].commingState;
					if(come == ""){
						jQuery.message.alert("您有未处理的诺访，请在到店情况确认是否到店后，才可新增诺访。");
						return;
					}
				}
				handlerAddRow(target);
			}
		});
	}
	
	function holdup(botton, table, form){
		if((/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/).test(jQuery("#mobile",form).val()) == false){
			jQuery.message.alert("请输入正确的手机号");
			return;
		}else{
			jQuery.ajaxsend({
				url:"/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
				data:{
							"entityClass":"com.app.miwawa.api.esm.entity.customer.Parents",
							"and[0][operator]": "EQ",
					    "and[0][fieldName]": "mobile",				
		          "and[0][fieldValue]": jQuery("#mobile",form).val()
				},
				success:function(data){
					var counts = data.rows;
					if(counts.length > 0){
						jQuery.message.alert("此手机号已存在，请更换。");
						return;
					}
					jQuery("#customerId",form).val(customer.customerid);
					handlerSubmit(botton, table, form);
				}
			});
		}
	}
	
	function changeMobile(botton, table, form){
		if((/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/).test(jQuery("#mobile",form).val()) == false){
			jQuery.message.alert("请输入正确的手机号");
			return;
		}else{
			jQuery.ajaxsend({
				url:"/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
				data:{
							"entityClass":"com.app.miwawa.api.esm.entity.customer.Parents",
							"and[0][operator]": "EQ",
					    "and[0][fieldName]": "mobile",				
		          "and[0][fieldValue]": jQuery("#mobile",form).val()
				},
				success:function(data){
					var counts = data.rows;
					if(counts.length > 0 && counts[0].id != jQuery("#parentid",form).val()){
							jQuery.message.alert("此手机号已存在，请更换。");
							return;
					}else{
						jQuery.ajaxsend({
							  url:"/miwawa/{dbname}/common/update".replace("{dbname}",dbname),
								data:{
									"entityClass":"com.app.miwawa.api.esm.entity.customer.Parents",
									"bean":{"id":jQuery("#parentid",form).val(),
													"relation":jQuery("form[name='editParents'] select[name='relation']").val(),
													"name":jQuery("#name",form).val(),
													"mobile":jQuery("#mobile",form).val()
									}
								},
								success:function(){
									handlerSubmit(botton, table, form);
								}
						});
					}
				}
			});
		}
	}
//-->
</script>